package com.report.controller;

import cn.zhxu.bs.BeanSearcher;
import cn.zhxu.bs.SearchResult;
import cn.zhxu.bs.operator.Contain;
import cn.zhxu.bs.util.MapUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.report.dto.response.LogRes;
import com.zmh.framework.sys.dto.request.SysLogRequestDTO;
import com.zmh.framework.util.Result;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author summer
 * @version 1.0
 * @date 2024/9/1 14:57
 */
@RestController
@RequestMapping(value = "/syslog")
@AllArgsConstructor
public class LogController {

    private final BeanSearcher beanSearcher;

    @PostMapping(value = "/lists")
    public Result<Page<LogRes>>  lists(@RequestBody SysLogRequestDTO sysLogRequestDTO){
        Map<String, Object> build = MapUtils.builder()
                .page(sysLogRequestDTO.getPageNum() - 1, sysLogRequestDTO.getPageSize())
                .field(LogRes::getNickName,sysLogRequestDTO.getUsername()).op(Contain.class).build();
        SearchResult<LogRes> search = beanSearcher.search(LogRes.class, build);
        Page<LogRes> page=new Page<>(sysLogRequestDTO.getPageNum() , sysLogRequestDTO.getPageSize());
        page.setTotal(search.getTotalCount().longValue());
        page.setRecords(search.getDataList());
        return Result.successResult(page);
    }
}
